#include "../include/acceptor.h"
#include "../include/tcpConnection.h"
#include "../include/eventLoop.h"
#include <iostream>
#include <unistd.h>

using std::cout;

void callBackNewConnection(const shared_ptr<TcpConnection> & con)
{
	cout << con->toString() << " 加入连接!\n ";
}

void callBackMessage(const shared_ptr<TcpConnection> & con)
{
	string msg = con->receive();

	cout << ">>客户端发来消息: " << msg << "\n";

	con->send("服务器收到消息： " + msg);
}

void callBackClose(const shared_ptr<TcpConnection> & con)
{
	cout << con->toString() << " 断开连接！\n";
}

int main()
{
	Acceptor acceptor("127.0.0.1",8888);

	acceptor.ready();

	EventLoop loop(acceptor);	
    loop.setNewConnectionCallBack(std::move(callBackNewConnection));
    loop.setMessageCallBack(std::move(callBackMessage));
    loop.setCloseCallBack(std::move(callBackClose));
	loop.loop();


	return 0;
}

















